# -*- coding: utf-8 -*-

# File Name： dc
# Description :
# Author : lirui
# create_date： 2022/9/15
# Change Activity:
from modules.generate_label.obj.cabinet import Cabinet


class DCContainer:
    def __init__(self, xls_info):
        self.xls_info = xls_info
        self.cabinet_mapping = self._build_cabinet_mapping(xls_info)
        pass

    @staticmethod
    def _build_cabinet_mapping(xls_info):
        """

        Args:
            xls_info:

        Returns:

        """
        mapping = {}
        for cabinet_name, info in xls_info.items():
            cab = Cabinet(info, cabinet_name)  # build object
            assert cabinet_name not in mapping
            mapping[cabinet_name] = cab
        return mapping

    def collect_labels(self):
        """

        Returns:

        """
        board_labels = {}
        u_labels = {}
        for cabinet_name, cabinet_info in self.cabinet_mapping.items():
            if cabinet_name not in board_labels:
                board_labels[cabinet_name] = {}
                u_labels[cabinet_name] = {}
            u_labels_mapping = cabinet_info.u_mapping
            for u_name, u_info in u_labels_mapping.items():
                u_labels[cabinet_name][u_name] = u_info.u_label
                if not u_info.is_rj45:
                    board_labels[cabinet_name][u_name] = u_info.board_label_lst
        return board_labels, u_labels
